<!DOCTYPE html>
<html  lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        车位申请
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}"></script>
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}">
    <!--导入ElementUI样式列表，css样式一般都在页面头部-->
    <link rel="stylesheet" th:href="@{/css/index.css}">
</head>
<bo>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>停车</cite></a>
              <a><cite>停车位申请</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" style="padding-top: 20px;" id="app">
    <div>
        <el-input v-model="searchMap.carCode" style="width: 20%" placeholder="请输入车牌号"></el-input>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <el-input v-model="searchMap.proposer" style="width: 20%" placeholder="请输入申请人名称"></el-input>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <el-button type="primary" plain @click="searchMap.pageNum=1;search()">搜索</el-button>
    </div>
    <br>
    <xblock>
        <button class="layui-btn layui-btn-danger" @click="delAll()">
            <i class="layui-icon">&#xe640;</i>批量删除</button>
        <button class="layui-btn" @click="admin_add('申请车位','parkingapplicationadd.html','1000','600')"><i
                class="layui-icon">&#xe608;</i>申请车位
        </button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <input type="checkbox" id="allChecked" :checked="checkedIDs.length===palist.length"
                       @click="allChecked">
            </th>
            <th>
                申请ID
            </th>
            <th>
                车牌号
            </th>
            <th>
                汽车品牌
            </th>
            <th>
                车辆类型
            </th>
            <th>
                颜色
            </th>
            <th>
                起租时间
            </th>
            <th>
                结租时间
            </th>
            <th>
                申请人
            </th>
            <th>
                申请结果
            </th>
            <th>
                操作
            </th>
        </tr>
        </thead>
        <tbody id="x-img">
        <tr v-for="(pa,index) in palist">
            <td>
                <input type="checkbox" :id="'id'+pa.id" :value="pa.id" v-model="checkedIDs">
            </td>
            <td>{{pa.id}}</td>
            <td>{{pa.carCode}}</td>
            <td>{{pa.carBrand}}</td>
            <td>{{pa.typeName}}</td>
            <td>{{pa.carColor}}</td>
            <td>{{dateFormat(pa.rentTime)}}</td>
            <td>{{dateFormat(pa.matchingTime)}}</td>
            <td>{{pa.proposer}}</td>
        <td v-if="pa.auditResult ==0">  <el-button size="mini"  type="primary" round>待审核</el-button></td>
        <td v-if="pa.auditResult =='通过'">  <el-button size="mini"  type="primary" round>审核通过</el-button></td>
        <td v-if="pa.auditResult =='不通过'">  <el-button size="mini"  type="primary" round>未通过</el-button></td>
            <td class="td-manage">
                &nbsp;<el-button   size="mini"    href="javascript:;"
                             @click="parkingapplicationadd_edit('编辑','parkingapplicationadd.html',pa.id,'1000','600')">编辑
                </el-button>
                <el-button   size="mini"    href="javascript:;"
                             @click="audit_result('审核信息','audit_result.html',pa.id,'1000','600')">审核
                </el-button>
                <el-button   size="mini"    href="javascript:;"
                             @click="del_one(pa.id)">删除
                </el-button>


<!--                <a title="删除" href="javascript:;" @click="del_one(pa.id)"-->
<!--                   style="text-decoration:none">-->
<!--                    <i class="layui-icon">&#xe640;</i>-->
<!--                </a>-->
<!--                <a></a>-->
            </td>
        </tr>
    </table>
        <el-pagination
                background
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :page-size="searchMap.pageSize"
                layout="prev, pager, next,sizes"
                :page-sizes="[2,10,20]"
                style="text-align: right;"
                :total="total">
        </el-pagination>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<!--js脚本一般是放在页面尾部-->
<!--Vue js脚本-->
<script th:src="@{/js/vue.js}" charset="utf-8"></script>
<!--引入ElementUI组件库-->
<script th:src="@{/js/index.js}" charset="utf-8"></script>
<!--引入Axios js脚本-->
<script th:src="@{/js/axios.js}" charset="utf-8"></script>
<!--引入时间插件包Momentjs-->
<script th:src="@{/js/moment.min.js}" charset="utf-8"></script>
<script>
    var app = new Vue({
        el: "#app",//声明当前Vue在页面的作用域、
        data:{
            checkedIDs:[],
            palist:[],
            total:10,
            searchMap:{"carCode":"","proposer":"","pageNum":1,"pageSize":2},
            selectDate:['',''],
            pickerOptions: {
            }
        },
        methods:{
            //分页查询停车列表
            search(){
                axios.post("/parkingapplication/search",this.searchMap).then((res)=>{
                    console.log(res)
                    app.palist = res.data.data;
                    app.total = res.data.total;
                });
            },
            //删除单个
            del_one(id){
                this.$confirm('请问你是否要删除该停车场信息','提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                    type:'waring',
                }).then(()=>{
                    //把选中的ID封装到集合中
                    this.checkedIDs.push(id);
                    //执行删除操作
                    axios.post("/parkingapplication/del",this.checkedIDs).then((res)=>{
                        if(res.data.flag){
                            this.$message({
                                type:'success',
                                message:'删除成功!'
                            });
                        }
                        //删除成功，把选中的id列表置空
                        this.checkedIDs = [];
                        //页面置为1，重新获取列表数据
                        this.searchMap.pageNum = 1;
                        this.search();
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //多选删除
            delAll(){
                this.$confirm('请问你是否要删除该停车场信息','提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                    type:'waring',
            }).then(() => {
                    //执行删除操作
                    axios.post("/parkingapplication/del", this.checkedIDs).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }
                        //删除成功，把选中的ID列表置为空
                        this.checkedIDs = [];
                        //把页面置为1，重新获取列表数据
                        this.searchMap.pageNum = 1;
                        this.search();
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //全选、全不选方法-
            allChecked: function () {
                if (this.checkedIDs.length === this.palist.length) {
                    // 全不选
                    this.checkedIDs = [];

                } else {
                    this.checkedIDs = [];
                    // 全选
                    this.depotList.forEach((item) => {
                        this.checkedIDs.push(item.id); // 与checkbox的value统一
                    })
                }
            },
            //handleSizeChange每页数量发生变化后触发的方法
            handleSizeChange(pageSize) {
                this.searchMap.pageSize = pageSize;
                this.search();
            },
            //handleCurrentChange页码变化触发方法
            handleCurrentChange(pageNum) {
                this.searchMap.pageNum = pageNum;
                this.search();
            },
            //时间区间发生改变，searcHMap中时间区间条件也要变化
            dateChange(){
                //没有选择时间区间或者清理时间条件，当前时间区间为空字符串
                if(this.selectDate == null || this.selectDate.length == 0){
                    this.searchMap.startTime = '';
                    this.searchMap.endTime = '';
                }else{
                    //当时间区间不为空，往searchMap中添加条件
                    if(this.selectDate[0] != null && this.selectDate[0] != ''){
                        this.searchMap.startTime = this.dateFormat(this.selectDate[0]);

                    }
                    if(this.selectDate[1] != null && this.selectDate[1] != ''){
                        this.searchMap.endTime = this.dateFormat(this.selectDate[1]);
                    }
                }

            },
            //日期格式化方法
            //date 要进行格式的日期 ；format 格式化的样式
            dateFormat(date,format){
                //默认格式化字符串"YYYY-MM-DD HH:mm:ss"
                if(format == null || format == ''){
                    format = "YYYY-MM-DD HH:mm:ss";
                }
                return moment(date).format(format);
            },
            /*添加*/
            admin_add(title, url, w, h) {
                this.x_admin_show(title, url, w, h);
            },
            //编辑
            parkingapplicationadd_edit(title, url, id, w, h) {
                url = url + "?id=" + id;
                this.x_admin_show(title, url, w, h);
            },
            //审核
            audit_result(title, url, id, w, h){
                url = url + "?id=" + id;
                this.x_admin_show(title, url, w, h);
            },
            /*弹出层*/
            /*
                参数解释：
                title	标题
                url		请求的url
                id		需要操作的数据id
                w		弹出层宽度（缺省调默认值）
                h		弹出层高度（缺省调默认值）
            */
            x_admin_show(title, url, width, height) {
                if (title == null || title == '') {
                    title = false;
                }
                ;
                if (url == null || url == '') {
                    url = "404.html";
                }
                ;
                if (width == null || width == '') {
                    width = 800;
                }
                ;
                if (height == null || height == '') {
                    height = ($(window).height() - 50);
                }
                ;

                layer.open({
                    type: 2,
                    area: [width + 'px', height + 'px'],
                    fix: false, //不固定
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    title: title,
                    content: url,
                    cancel: function (index, layero) {
                        //使用右上角x关闭弹窗层，回调方法，重新加载页面数据，让修改或者新增的数据立马显示在页面上
                        app.search();
                    }
                });
            },
            /*关闭弹出框口*/
            x_admin_close() {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        },
        created: function () {//Vue生命周期方法，加载页面时会执行该方法
            layui.use(['laydate', 'element', 'laypage', 'layer'], function () {
                $ = layui.jquery;//jquery
                layer = layui.layer;//弹出层
                okLoading.close($);
                layer.ready(function () { //为了layer.ext.js加载完毕再执行
                    layer.photos({
                        photos: '#x-img'
                    });
                });
            });
            //初始页面获取小区列表信息
            this.search();

        }
    });

</script>

    </bo>
    </html>